package org.jsbd.boss.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.jsbd.boss.domian.statistics.AppAction;
import org.jsbd.boss.domian.statistics.SDKRate;
import org.jsbd.boss.service.IAppActionService;
import org.jsbd.boss.service.ISdkRateService;
import org.jsbd.boss.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/app/action")
public class AppActionController {

	private static final Logger logger = LoggerFactory.getLogger(AppActionController.class);

	@Resource
	private IAppActionService appActionService;

	/**
	 * APP行为统计页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "/list")
	public String list() {
		return "appAction/appActionList";
	}

  	/**
  	 * APP行为统计数据
  	 * 
  	 * @param model
  	 * @param startTime
  	 * @return
  	 */
  	@RequestMapping(value = "/listData", method = RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> listData(Model model, String startTime, String mark) {
  		Map<String, Object> map = new HashMap<String, Object>();
  		if (StringUtils.isBlank(startTime)) {
  			startTime = DateUtil.getCurrentDateFormatStr(DateUtil.DATE_PATTEN_YYMMDD);
  		} else {
  			startTime = startTime.replace("-", "");
  		}
  		if (StringUtils.isBlank(mark)) {
  			mark = appActionService.getOneMark(startTime);
  		}
  		
  		List<String> xAxis = appActionService.getXaxis(startTime, mark);
  		List<AppAction> yAxis = appActionService.getYaxis(startTime, mark);
  		
  		map.put("mark", mark);
		map.put("xAxis", xAxis);
		map.put("yAxis", yAxis);
		
		return map;
	}

}
